package com.itheima.Demo01.Throw;

import java.util.Scanner;

public class Test01  {
    public static void main(String[] args) {
        Student S= new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名");
        String name = sc.next();
        S.setName(name);
        while (true) {
            try {
                System.out.println("请输入学生年龄");
                int age = sc.nextInt();
                S.setAge(age);
                if (age <= 24 && age >= 18) {
                    S.setAge(age);
                    System.out.println("输入正确");
                    break;
                }else {
                    throw new Exception();
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("请重新输入");
            }
        }
        System.out.println("学生姓名为"+S.getName()+"---"+"学生年龄为"+S.getAge());
    }
}
